package com.bible.fire.util;

import com.bible.fire.R;
import com.bible.fire.local.AppContext;
import com.bible.fire.local.RuntimeContext;
import com.bible.fire.pad.activity.surface.DesktopActivity;
import com.bible.fire.service.RestartAppService;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class ViewUtil {
	private static String TAG = ViewUtil.class.getSimpleName();
	
	public static View getQuitView4Exception( Context context ){
		View view = View.inflate(context, R.layout.restart_app_tip, null);
		View btn = view.findViewById( R.id.btn_restartApp );
		btn.setOnClickListener(new OnClickListener() {
	         @Override
	         public void onClick(View v) {
	        	 Log.d(TAG, "start to end app....");
	        	 Intent intent = new Intent();  
	             // 参数1：包名，参数2：程序入口的activity
	        	 Context gContext = AppContext.getContext();
	             intent.setClassName(gContext.getPackageName(), DesktopActivity.class.getName()); 
	             
	             PendingIntent restartIntent = PendingIntent.getActivity( gContext, 0,  
	                     intent, Intent.FLAG_ACTIVITY_NEW_TASK); 
	             AlarmManager mgr = (AlarmManager)gContext.getSystemService(Context.ALARM_SERVICE);  
	             mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, restartIntent); // 1秒钟后重启应用  
	             RuntimeContext.finishRuntimeApp(); // 自定义方法，关闭当前打开的所有avtivity
	         }
	     });
		return view;
	}

}
